home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / tweak16b.zip / EXAMPLE1.C < prev    next >
C/C++ Source or Header  |  1993-11-29  |  2KB  |  88 lines

  1. /*
  2.     Example1.C version 1.5
  3.     by Robert Schmidt of Ztiff Zox Softwear 1993
  4.  
  5.     Example of making use of a TWEAK file by loading it directly at
  6.         run-time.  This program needs the file(s) created by TWEAK
  7.         available at run-time.
  8. */
  9.  
  10. #include <dos.h>
  11. #include <mem.h>
  12. #include <alloc.h>
  13. #include <conio.h>
  14. #include "TwkUser.h"    /* declares the neccessary functions and types */
  15.  
  16. main()
  17.     {
  18.     /* Define the pointer that should point to the loaded array of
  19.        Registers, and the int to hold its size */
  20.  
  21.     RegisterPtr rarray;
  22.     int rsize;
  23.  
  24.     int y, lastMode;
  25.  
  26.     cprintf("This example program loads a TWEAK register file at run-time\n\r");
  27.     cprintf("and uses this to set Mode X (320x240x256).\n\rPress any key.");
  28.     getch();
  29.  
  30.     /* Now use the loadRegArray function declared in TwkUser.h to load the
  31.        TWEAK file.  Memory is automatically allocated.  Note that the
  32.        second argument is the address of the pointer defined above!
  33.        The returned value is the number of Register elements loaded. */
  34.  
  35.     rsize = loadRegArray("320x240.256", &rarray);
  36.  
  37.     /* Save the number of the current BIOS mode, so we can restore it
  38.        later. */
  39.  
  40.     _AH = 0x0f;
  41.     geninterrupt(0x10);
  42.     lastMode = _AL;
  43.  
  44.     /* Set mode 13h, to make sure the EGA palette set is correct for a 256
  45.        color mode */
  46.  
  47.     _AX = 0x13;
  48.     geninterrupt(0x10);
  49.  
  50.     /* rarray now points to the loaded array.  The second argument to
  51.        outRegArray is the number if Register elements in the array. */
  52.  
  53.     outRegArray(rarray, rsize);
  54.  
  55.     outpw(0x3c4, 0x0f02);            /* Enable all 4 planes */
  56.  
  57.     /* Fill the screen with a blend of pink and green lines, defining the
  58.        palette on the fly. */
  59.  
  60.     outp(0x3c8, 0);                    /* start with color 0 */
  61.     for (y = 0; y<240; y++)
  62.         {
  63.         outp(0x3c9, y>>2);            /* red component */
  64.         outp(0x3c9, (256-y) >> 2);    /* green component */
  65.         outp(0x3c9, y>>2);            /* blue component */
  66.         memset((char*)MK_FP(0xa000,0) + y*80, y, 80);
  67.         }
  68.  
  69.     /* The mode is now set, so wait for the user to press a key...
  70.        Nothing much interesting to look at, I'm afraid. */
  71.  
  72.     getch();
  73.  
  74.     /* Restore the saved mode number.  Borland's textmode() won't work, as the
  75.        C library still thinks we're in the mode it detected at startup.
  76.        The palette will be set to the BIOS mode's default. */
  77.  
  78.     _AX = lastMode;
  79.     geninterrupt(0x10);
  80.  
  81.     /* Free the Register array allocated in loadRegArray.  *You* are
  82.        responsible for doing this! */
  83.  
  84.     free(rarray);
  85.  
  86.     return 0;
  87.     }
  88.